package com.xiaotu.service.impl;

import com.xiaotu.Rrepository.PersonRepository;
import com.xiaotu.entity.Person;
import com.xiaotu.service.PersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class PersonServiceImpl implements PersonService {
    @Autowired
    private PersonRepository personRepository;
    @Override
    public List<Person> findAll() {
        return personRepository.findAll();
    }
    @Override
    @Transactional
    public void add(Person person) {
        personRepository.save(person);
    }
    @Override
    @Transactional
    public void delete(Long id) {
        personRepository.deleteById(id);
    }
    @Override
    @Transactional
    public void update(Person person){
        personRepository.saveAndFlush(person);
    }
}
